package game.roles.bullets;

import game.frame.MainFrame;
import game.roles.Role;
import game.roles.enemys.EnemyRole;
import game.roles.visual.Blast;
import game.utils.ImageChange;

import java.awt.*;

/**
 * @author liuyulai
 * Created with IntelliJ IDEA.
 * Date: 21.5.12
 * Time: 11:44
 * Description: No Description
 */
public class IceBullet extends Role implements GamerBullet {
    /**
     * 子弹1
     */
    public static Image[] bullet2;

    private ImageChange rm = new ImageChange(3);

    /**
     * 方向初始化
     */
    private int direction;

    /**
     * 子弹初始化
     */
    public IceBullet(int x, int y, int direction) {
        super(x + 35, y + 15, 10, 10);
//        this.img = bullet2;
        this.direction = direction;
    }


    @Override
    public void rolesMove() {

        this.img = rm.change(bullet2);

        if (this.direction == LEFT_UP) {
            this.x -= 15;
            this.y += 20;
        } else if (this.direction == LEFT_DOWN) {
            this.x -= 15;
            this.y -= 20;
        } else if (this.direction == RIGHT_UP) {
            this.x += 15;
            this.y += 20;
        } else if (this.direction == RIGHT_DOWN) {
            this.x += 15;
            this.y -= 20;
        } else if (this.direction == BACK) {
            this.x -= 30;
        } else if (this.direction == FRONT) {
            this.x += 30;
        } else if (this.direction == UP) {
            this.y -= 10;
        }

        for (int i = 0; i < MainFrame.roleList.size(); i++) {
            Role r = MainFrame.roleList.get(i);
            if (r instanceof EnemyRole && this.rec.intersects(r.rec)) {
                EnemyRole s1 = (EnemyRole) r;
                s1.byHit(60);
                MainFrame.roleList.remove(this);
                MainFrame.roleList.add(new Blast(this.x, this.y));
                return;
            } else if (r instanceof EnemyBullet && this.rec.intersects(r.rec)) {
                MainFrame.roleList.remove(r);
                MainFrame.roleList.add(new Blast(this.x, this.y));
                i--;
            }
        }
    }
}
